package com.biunova.novapay.controller;

import com.biunova.novapay.entity.Order;
import com.biunova.novapay.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrderController {

    private final OrderService orderService;

    @Autowired
    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    @PostMapping
    public String createOrder(@RequestBody Order order) {
        orderService.createOrder(order);
        return "Order created successfully";
    }

    @PutMapping("/{id}")
    public String updateOrder(@PathVariable Long id, @RequestBody Order order) {
        order.setOrderId(id);
        orderService.modifyOrder(order);
        return "Order updated successfully";
    }

    @DeleteMapping("/{id}")
    public String deleteOrder(@PathVariable Long id) {
        orderService.removeOrder(id);
        return "Order deleted successfully";
    }

    @GetMapping("/{id}")
    public Order getOrderById(@PathVariable Long id) {
        return orderService.fetchOrderById(id);
    }

    @GetMapping
    public List<Order> getAllOrders() {
        return orderService.fetchAllOrders();
    }
}
